<?php
	global $post;
	$args = array(
		'post_type' =>'highlights',
		'numberposts' => -1,
		'orderby' => 'ASC'
	);
	$highlights_posts = get_posts($args);
?>
<?php if($highlights_posts) { ?>
<div id="homepage-highlights" class="clearfix">
	<?php
    $i=0; //start post count at "0"
    foreach($highlights_posts as $post) : setup_postdata($post);
    $i++; //add 1 to the total count
    ?>
    <div class="homepage-highlight  <?php if($i===3){ echo 'remove-margin'; } ?>">
        <h2><?php the_title(' '); ?></h2>
        <?php if ( has_post_thumbnail() ) {  ?>
        <div class="homepage-highlight-thumbnail">
            <?php
            //check if highlight URL exists and show link
            $key = 'highlights_url';
            $themeta = get_post_meta($post->ID, $key, TRUE);
            if($themeta != '') { ?>
            <a href="<?php echo $themeta ?>" title="<?php the_title(' ') ?>"><?php the_post_thumbnail('home-highlights'); ?></a>
            <?php } else { ?>
            <?php the_post_thumbnail('home-highlights'); ?>
            <?php } ?>
        </div>
        <!-- END homepage-highlight-thumbnail -->
        <?php } ?>
        <?php the_content(' '); ?>
    </div>
    <!-- END homepage-highlight -->
    <?php
    //reset the count to "0" and clear the divs
    if($i===3){ echo '<div class="clear"></div>'; $i=0; } ?>
    <?php endforeach; ?>
</div>
<!--END homepage-highlights -->
<?php } wp_reset_postdata(); ?>